﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Business = SoTaiChinh.Library.Business;
using Entity = SoTaiChinh.Library.Entity;

public partial class templates_client_usercontrols_detail_news : System.Web.UI.UserControl
{
    Entity.TinTuc clsE_TinTuc = new SoTaiChinh.Library.Entity.TinTuc();
    Business.TinTuc clsB_TinTuc = new SoTaiChinh.Library.Business.TinTuc();
    Entity.BinhLuan clsE_BinhLuan = new SoTaiChinh.Library.Entity.BinhLuan();
    Business.BinhLuan clsB_BinhLuan = new SoTaiChinh.Library.Business.BinhLuan();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string id = Request.QueryString["news"].ToString();
            clsE_TinTuc.Id = Convert.ToInt32(id);
            clsB_TinTuc.UpdateLuotXem(clsE_TinTuc); 
            rptnew.DataSource = clsB_TinTuc.SelectPrimarykey(clsE_TinTuc);
            rptnew.DataBind();
            Label allow_comt = (Label)rptnew.Items[0].FindControl("allow_comt");
            Label title = (Label)rptnew.Items[0].FindControl("title");
            Page.Title = title.Text;
            bool allow = Boolean.Parse(allow_comt.Text);
            rptnew.Items[0].FindControl("frm_binhLuan").Visible = allow;
            if (allow == true)
            {
                rptnew.Items[0].FindControl("vietbinhluan").Visible = false;
                rptnew.Items[0].FindControl("controlbinhluan").Visible = false;
                
            }
        }
    }   
    protected void rptnew_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        try
        {            
            if (e.CommandName == "ykien")
            {
                rptnew.Items[0].FindControl("vietbinhluan").Visible = true;
                rptnew.Items[0].FindControl("controlbinhluan").Visible = true;
                TextBox hoten = (TextBox)rptnew.Items[0].FindControl("txtHoTen");
                hoten.Focus();
            }
            if (e.CommandName == "send")
            {
                bool save = false;
                string baiviet = Request.QueryString["news"].ToString();
                clsE_BinhLuan.BaiViet = Convert.ToInt32(baiviet);
                TextBox hoten = (TextBox)rptnew.Items[0].FindControl("txtHoTen");
                clsE_BinhLuan.TenDayDu = hoten.Text;
                TextBox tieude = (TextBox)rptnew.Items[0].FindControl("txtTieuDe");
                clsE_BinhLuan.TieuDe = tieude.Text;
                TextBox email = (TextBox)rptnew.Items[0].FindControl("txtEmail");
                clsE_BinhLuan.Email = email.Text;
                TextBox noidung = (TextBox)rptnew.Items[0].FindControl("txtNoiDung");
                clsE_BinhLuan.NoiDung = noidung.Text;
                clsE_BinhLuan.NgayDang = DateTime.Now;
                clsE_BinhLuan.TrangThai = true;
                save=clsB_BinhLuan.Insert(clsE_BinhLuan);
                if (save)
                {
                    Alert.Show("Đăng ý kiến bình luận thành công !!!");
                }
                else
                {
                    Alert.Show("Đăng ý kiến bình luận không thành công !!!");
                }
            }
            if (e.CommandName == "close")
            {
                rptnew.Items[0].FindControl("vietbinhluan").Visible = false;
                rptnew.Items[0].FindControl("controlbinhluan").Visible = false; 
            }
        }
        catch
        { }
    }
}
